package com.hxzy.shop.dto.coupon.convert;


import com.hxzy.shop.dto.coupon.req.CouponEditReq;
import com.hxzy.shop.dto.coupon.req.CouponSaveReq;
import com.hxzy.shop.dto.coupon.resp.CouponListResp;
import com.hxzy.shop.entity.Coupon;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

import java.util.Date;
import java.util.List;

/**
 * @Author ht
 * @Date 2021/7/8 9:03
 * @Version 1.0
 */
@Mapper
public abstract class CouponConvert {
    public static CouponConvert INSTANCE = Mappers.getMapper(CouponConvert.class);
    public abstract Coupon couponSaveReq2Coupon(CouponSaveReq couponSaveReq);

    @AfterMapping
    public void req2Coupon(CouponSaveReq couponSaveReq,@MappingTarget Coupon coupon){
        coupon.setCreateTime(new Date());
        coupon.setState(Boolean.TRUE);
        coupon.setActivate(Boolean.FALSE);
        coupon.setSurplusStock(couponSaveReq.getStock());
        coupon.setStatusOfRecipients(1);
    }

    public abstract Coupon couponEditReq2Coupon(CouponEditReq couponEditReq);
    public abstract List<CouponListResp> coupon2CouponListResp(List<Coupon> coupon);
}
